﻿using Microsoft.Extensions.DependencyInjection;
using MQTTnet.Server;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
using Volo.Abp.DependencyInjection;

namespace Artizan.Iot.Hub.Mqtt.Server
{
    public class MqttServerService: IMqttServerService, ISingletonDependency
    { 
        private readonly IServiceProvider _serviceProvider;

        public MqttServer MqttServer { get; private set; }

        public MqttServerService(IServiceProvider serviceProvider)
        {
            _serviceProvider = serviceProvider;
        }

        public void ConfigureMqttService(MqttServer mqttServer)
        {
            MqttServer =  mqttServer;

            var mqttServices = _serviceProvider.GetServices<IMqttService>();
            foreach (var mqttService in mqttServices)
            {
                mqttService.ConfigureMqttServer(mqttServer);
            }
        }
    }
}
